package com.blog.controller;

import com.blog.pojo.Tag;
import com.blog.service.ArticleService;
import com.blog.service.TagService;
import com.blog.service.impl.ArticleServiceImpl;
import com.blog.service.impl.TagServiceImpl;
import com.blog.utils.DateUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * 跳转到新增文章的页面
 */
@WebServlet("/GoAddArticelServlet.do")
public class GoAddArticelServlet extends HttpServlet {

    ArticleService articleService=new ArticleServiceImpl();
    TagService tagService=new TagServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //加载所有的博客分类分类
        Map<String, Integer> sort_count = articleService.getArticleSortAndCount();
        req.setAttribute("sort_count",sort_count);

        //加载标签
        List<Tag> all_tag = tagService.getTags();
        req.setAttribute("all_tag",all_tag);

        //加载时间
        String time= DateUtils.now();
        req.setAttribute("time",time);

        //跳转新增文章页面
        req.getRequestDispatcher("/admin/add.jsp").forward(req,resp);
    }
}
